var ctxPath = "/education";

$.getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
};

!function ($) {

    var orderCode = $.getUrlParam('orderCode');


    var initOrderDetail = function(orderCode) {
        $.ajax({
            url: ctxPath + '/wx/api/order/getOrderByCode',
            type: 'post',
            dataType: 'json',
            data: {orderCode: orderCode},
            success: function (result) {
                if(result.returnCode == 0) {

                    $("#orderPayBtn").hide();
                    if(result.orderStatus == 'UN_PAYED'){
                        $("#orderDesc").html("您的订单正在等待支付");
                        $("#orderPayBtn").show();
                    }else if(result.orderStatus == 'ORDERED'){
                        $("#orderDesc").html("您的订单已经报名，正在等待线下联系");
                    }else if(result.orderStatus == 'PAYED'){
                        $("#orderDesc").html("您的订单已支付，正在等待发货");
                    }else if(result.orderStatus == 'COMPLETE'){
                        $("#orderDesc").html("您的订单已完成交易，感谢支持");
                    }

                    $("#orderCode").html("订单编号:" + result.orderCode);
                    $("#orderImage").attr("src", result.showImage);
                    $("#productName").html(result.productName);
                    $("#applicantName").html(result.applicantName);
                    $("#groupName").html(result.groupName);
                    $("#phone").html(result.phone);
                    $("#schoolGradeClazz").html(result.schoolGradeClazz);
                    $(".productDeposit").html("<em>¥</em>" + result.productDeposit);
                    $(".orderTime").html("下单时间:" + result.orderTime);
                } else {
                    alert(result.returnMsg);
                }
            }
        });
    };

    initOrderDetail(orderCode);

    $("#orderPayBtn").click(function () {
        //事件
        location.href = ctxPath + "/wx/productPay.html?orderCode=" + orderCode;
    })

}(jQuery);